package com.atguigu.srb.core.controller.api;


import com.atguigu.srb.base.response.R;
import com.atguigu.srb.core.service.LendItemService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;

/**
 * <p>
 * 标的出借记录表 前端控制器
 * </p>
 *
 * @author Atguigu
 * @since 2023-05-26
 */
@RestController
@RequestMapping("/api/core/lendItem")
public class ApiLendItemController {
    @Resource
    LendItemService lendItemService;
    @ApiOperation("根据标的id查询投资记录")
    @GetMapping("list/{lendId}")
    public R listByLendId(@PathVariable("lendId")String lendId){
        return R.ok().data("items",lendItemService.listByLendId(lendId));
    }
    @ApiOperation("投资")
    @PostMapping("/auth/commitInvest/{amount}/{lendId}")
    public R commitInvest(@RequestHeader("token") String token,
                          @PathVariable("amount") BigDecimal amount,
                          @PathVariable("lendId") String lendId) {
        String form = lendItemService.commitInvest(token, amount, lendId);
        return R.ok().data("form", form);
    }

    @ApiOperation("投资回调接口")
    @PostMapping("/notify")
    public String investNotify(HttpServletRequest request) {
        return lendItemService.investNotify(request);
    }
}

